﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleLibrary
{
    public class LocalData
    {
        public Random myRandom = null;
        
        public LocalData()
        {
            myRandom = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
            myStatus = LocalStatus.None;
        }

        // Init Pointer For each thread
        public void InitDatFilePointer()
        {
            foreach (string strTableName in SqlLoadGen.myFiles)
            {
                myPointers.Add(strTableName, myValue-1);
            }
        }

        //Set Pointer
        public void SetPointer(string strTableName,int iPointer)
        {
            // If there's only autogen field, we don't need to set pointer.
            if (string.IsNullOrEmpty(strTableName))
            {
                return;
            }
            // check whether pointer reached to max row number
            if (iPointer >= (SqlLoadGen.dsCSVs.Tables[strTableName].Rows.Count-1))
            {
                iPointer = myValue - 1;
            }
            myPointers[strTableName] = iPointer;
        }
        
        public Hashtable myPointers = new Hashtable();
        public LocalStatus myStatus;
        public int myValue = 0;
    }

    public enum LocalStatus
    {
        None,
        Started,
        Running,
        Ended
    }
}
